import { defineStore } from 'pinia'
import { reqCategory } from '../../api/home'
import type { bannerList, categoryItemList } from '../../api/home/mudul';

export const indexCategory = defineStore({
  id: "indexCategory",
  state: () => ({
    // 分类banner
    banner: <bannerList[]>[],
    // 分类item
    categoryItemList: <categoryItemList>[],
    itemState: false
  }),

  actions: {

    async getCategory(categoryId: string) {
      
        this.itemState = true
        let res = await reqCategory(categoryId)
        this.banner = res.data.data.currentCategory.bannerList
        this.categoryItemList = res.data.data.categoryItemList.slice(0, 20)
        this.itemState = false
    }
  }
})
